| Conditions | 4 |
| Paths | 10 |
| Total Lines | 143 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | (function ($) { |
||
| 93 | var stateBarMenu = function () { |
||
| 94 | |||
| 95 | var ACTIVE_THRESHOLD = 55; |
||
| 96 | |||
| 97 | $.fn.isVisible = function (type) { |
||
| 98 | // Current distance from the top of the page |
||
| 99 | var windowScrollTopView = $(window).scrollTop(); |
||
| 100 | // Current distance from the top of the page, plus the height of the window |
||
| 101 | var windowBottomView = windowScrollTopView + $(window).height(); |
||
| 102 | // Element distance from top |
||
| 103 | var elemTop = $(this).offset().top; |
||
| 104 | // Element distance from top, plus the height of the element |
||
| 105 | if (type == "top") { |
||
| 106 | offset = 50; |
||
| 107 | } else if (type == "button") { |
||
| 108 | offset = 15; |
||
| 109 | } else { |
||
| 110 | offset = +380; |
||
| 111 | } |
||
| 112 | var elemBottom = elemTop + $(this).height() + offset; |
||
| 113 | //console.log("wTop " + windowScrollTopView + " wB " + windowBottomView + " eTop" + elemTop); |
||
| 114 | return ((elemBottom <= windowBottomView) && (elemTop >= windowScrollTopView)); |
||
| 115 | }; |
||
| 116 | |||
| 117 | |||
| 118 | if ($('.state-bar').length == 0) return; |
||
| 119 | var fixBarTop = $('.state-bar').offset().top; |
||
| 120 | var donationSection = $("#donation-amount").offset().top; |
||
| 121 | var donationPaymentSection = $("#donation-payment").offset().top; |
||
| 122 | var donationTypeSection = $("#donation-type").offset().top; |
||
| 123 | |||
| 124 | if ($(window).width() < 1023) { |
||
| 125 | $(window).scroll(function () { |
||
| 126 | var currentScroll = $(window).scrollTop(); |
||
| 127 | if (currentScroll + 70 >= fixBarTop) { |
||
| 128 | $('.state-bar').addClass('active'); |
||
| 129 | $('.fixed-button').addClass('active'); |
||
| 130 | $('.menu-main').addClass('under-bar'); |
||
| 131 | |||
| 132 | if ($('.footer').isVisible('top')) { |
||
| 133 | $('.menu-main').removeClass('under-bar'); |
||
| 134 | } else { |
||
| 135 | $(".state-bar").addClass('active'); |
||
| 136 | $('.menu-main').addClass('under-bar'); |
||
| 137 | } |
||
| 138 | |||
| 139 | if ($('#submit-bottom').isVisible('button')) { |
||
| 140 | $('.fixed-button').removeClass('active'); |
||
| 141 | } else { |
||
| 142 | $('.fixed-button').addClass('active'); |
||
| 143 | } |
||
| 144 | |||
| 145 | } else { |
||
| 146 | $('.state-bar').removeClass('active'); |
||
| 147 | $('.menu-main').removeClass('under-bar'); |
||
| 148 | } |
||
| 149 | if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 150 | $('.state-overview .amount').addClass('enabled'); |
||
| 151 | } else { |
||
| 152 | $('.state-overview .amount').removeClass('enabled'); |
||
| 153 | } |
||
| 154 | |||
| 155 | |||
| 156 | |||
| 157 | }); |
||
| 158 | } else { |
||
| 159 | $(window).scroll(function () { |
||
| 160 | var currentScroll = $(window).scrollTop(); |
||
| 161 | if ($('.page-donation').length) { |
||
| 162 | var initialTop = 200; |
||
| 163 | } else if ($('.page-membership').length) { |
||
| 164 | var initialTop = 650; |
||
| 165 | } |
||
| 166 | |||
| 167 | |||
| 168 | if (currentScroll >= initialTop) { |
||
| 169 | $('.state-overview .wrap-bar').addClass('fixed'); |
||
| 170 | //console.log("wrap bar" + currentScroll); |
||
| 171 | } else { |
||
| 172 | $('.state-overview .wrap-bar').removeClass('fixed'); |
||
| 173 | } |
||
| 174 | |||
| 175 | |||
| 176 | if (($('.state-bar-lateral .wrap-bar').outerHeight() + $('.state-bar-lateral .wrap-bar').offset().top ) > ( $('.form-shadow-wrap').offset().top + $('.form-shadow-wrap').outerHeight() + 150)) { |
||
| 177 | $('.state-bar-lateral').removeClass('active'); |
||
| 178 | } else { |
||
| 179 | $('.state-bar-lateral').addClass('active'); |
||
| 180 | } |
||
| 181 | }); |
||
| 182 | } |
||
| 183 | |||
| 184 | // TODO Include this only on mebership pages |
||
| 185 | if ($(".page-membership").length) { |
||
| 186 | var memberTypeSection = $("#membership-type").offset().top; |
||
| 187 | $(window).scroll(function () { |
||
| 188 | var currentScroll = $(window).scrollTop(); |
||
| 189 | var typeMemberElements = $('.state-overview .member-type'); |
||
| 190 | var donorElements = $('.state-overview .donor-type'); |
||
| 191 | var amountElements = $('.state-overview .amount'); |
||
| 192 | var paymentElemnts = $('.state-overview .payment-method'); |
||
| 193 | |||
| 194 | typeMemberElements.removeClass('enabled'); |
||
| 195 | donorElements.removeClass('enabled'); |
||
| 196 | amountElements.removeClass('enabled'); |
||
| 197 | paymentElemnts.removeClass('enabled'); |
||
| 198 | ACTIVE_THRESHOLD = 60; |
||
| 199 | if (currentScroll >= donationPaymentSection - ACTIVE_THRESHOLD) { |
||
| 200 | paymentElemnts.addClass('enabled'); |
||
| 201 | } |
||
| 202 | else if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 203 | amountElements.addClass('enabled'); |
||
| 204 | } |
||
| 205 | else if (currentScroll >= donationTypeSection - ACTIVE_THRESHOLD) { |
||
| 206 | donorElements.addClass('enabled'); |
||
| 207 | } |
||
| 208 | else if (currentScroll >= memberTypeSection - ACTIVE_THRESHOLD) { |
||
| 209 | typeMemberElements.addClass('enabled'); |
||
| 210 | } |
||
| 211 | }); |
||
| 212 | } else { |
||
| 213 | // TODO include only on donation pages? |
||
| 214 | $(window).scroll(function () { |
||
| 215 | var currentScroll = $(window).scrollTop(); |
||
| 216 | var amountElements = $('.state-overview .amount'); |
||
| 217 | var paymentElemnts = $('.state-overview .payment-method'); |
||
| 218 | var donorElements = $('.state-overview .donor-type'); |
||
| 219 | |||
| 220 | amountElements.removeClass('enabled'); |
||
| 221 | paymentElemnts.removeClass('enabled'); |
||
| 222 | donorElements.removeClass('enabled'); |
||
| 223 | if (currentScroll >= donationTypeSection - ACTIVE_THRESHOLD) { |
||
| 224 | donorElements.addClass('enabled'); |
||
| 225 | } |
||
| 226 | else if (currentScroll >= donationPaymentSection - ACTIVE_THRESHOLD) { |
||
| 227 | paymentElemnts.addClass('enabled'); |
||
| 228 | } |
||
| 229 | else if (currentScroll >= donationSection - ACTIVE_THRESHOLD) { |
||
| 230 | amountElements.addClass('enabled'); |
||
| 231 | } |
||
| 232 | }); |
||
| 233 | } |
||
| 234 | |||
| 235 | }; |
||
| 236 | |||
| 238 |
This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.
To learn more about declaring variables in Javascript, see the MDN.